package offertest.test04;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @ClassName MyThreadPool
 * @Description
 * @Author ZJX
 * @Date 2025/4/12 21:06
 * @Version 1.0
 **/
public class MyThreadPool {
    private BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(10);

    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(()->{
                while (true){
                    Runnable take = null;
                    try {
                        take = queue.take();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    take.run();
                }
            });
        }
    }

    void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
}
